package com.edu.interceptor;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;
import java.util.Date;

/**
 * @Author:何包蛋
 * @Date :2022/11/2 - 11 - 02 - 23:20
 */
public class LogInterceptor implements MethodInterceptor {

    private Object target;

    public LogInterceptor(Object target) {
        this.target = target;
    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        System.out.println(method.getName()+"执行于"+new Date());
        Object result = method.invoke(target, objects);

        return result;
    }
}
